Skip to content

added the reconnect timeout#2026

Open
Ankit8969 wants to merge 4 commits intonovnc:masterfrom
Ankit8969:reconnect_timeout
Open

added the reconnect timeout#2026
Ankit8969 wants to merge 4 commits intonovnc:masterfrom
Ankit8969:reconnect_timeout

Conversation

@Ankit8969
Copy link
Copy Markdown

This update introduces a maximum reconnect timeout for the VNC client. Currently, when the VNC client attempts to reconnect, it may continue retrying indefinitely if the connection keeps failing, which is not ideal.

With this change, we add a new configuration key, reconnect_max_time, in default.json. This setting allows us to define a maximum duration for reconnection attempts. Once the specified time limit is reached, the client will stop trying to reconnect, preventing unnecessary retries and improving overall stability.

@Ankit8969
Copy link
Copy Markdown
Author

@samhed, please check this PR

Copy link
Copy Markdown
Member

@samhed samhed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. I didn't test it yet, but a few comments from briefly checking the code.

Comment thread app/ui.js Outdated
Comment thread app/ui.js Outdated
@samhed samhed added the feature label Mar 24, 2026
@Ankit8969 Ankit8969 requested a review from samhed March 27, 2026 05:41
Copy link
Copy Markdown
Member

@samhed samhed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this and unfortunately, this breaks the reconnection functionality. No matter what I set reconnect_max_time to, the first time reconnect() is called, we abort the reconnection attempts. This is because UI.firstReconnectTime is never set.

I get the impression that you're not testing your code?

Comment thread defaults.json
{}
{
"reconnect_max_time": 600000
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is that this should be empty. You will still get the same behavior since you added a default when calling UI.getSetting().

defaults.json could be used by integrators of the noVNC app to provide other defaults.

Comment thread app/ui.js
if (UI.firstReconnectTime === null) {
UI.firstReconnectTime = Date.now();
}
const elapsedTime = Date.now() - UI.firstReconnectTime;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you're not using this variable.

Comment thread app/ui.js
UI.closePowerPanel();
}
},
resetFirstReconnection(){
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space before {

Comment thread app/ui.js
}
UI.showStatus(msg);
UI.updateVisualState('connected');
// Here we can reset the retry count
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

misleading comment

Comment thread app/ui.js
const maxTime = UI.getSetting('reconnect_max_time') ?? 600000; // default to 10 minutes => 10 * 60 * 1000 ms

// Initialize first reconnect time if it's the first attempt
if (UI.firstReconnectTime === null) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI.firstReconnectTime is never null, meaning your logic never works. Did you mean to check for 0?

Comment thread app/ui.js

reconnect() {
UI.reconnectCallback = null;
const maxTime = UI.getSetting('reconnect_max_time') ?? 600000; // default to 10 minutes => 10 * 60 * 1000 ms
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this should be configured to seconds instead of milliseconds?

I.e:

const maxTime = UI.getSetting('reconnect_max_time') ?? 600; // default to 10 minutes => 10 * 60 seconds

...

// Check if we've exceeded the max reconnect time
if ((Date.now() - UI.firstReconnectTime) >= maxTime * 1000) {

@samhed samhed added the ui/full label Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants